﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Ianelli_Tactics
{
    class Character
    {


        #region attributes

        #region on_battle_attributes
        /// <summary>
        /// health: Character Health.
        /// movement_points: Points used for moving your character (Refill on every turn).
        /// attack_points: Points used for attacking. (Refill on every turn).
        /// team: Team 1 (Attackers) or 2 (Defendants), depending on the battle.
        /// strenght: Main attribute for OFFENSE. Used to calculate dmg done by melee attacks.
        /// agility: Used for CT charge. More agility, faster it charges.
        /// endurance: Higher endurance means higher health points and resistances.
        /// luck: Used on calculations for critical hits and drops at end of battles.
        /// </summary>
        public int health, movement_points, attack_points, team, strenght, agility, endurance, luck;

        /// <summary>
        /// chargeTime (CT) is used to check who'll play first. Characters with high agility recover the CT faster.
        /// </summary>
        public float chargeTime;

        /// <summary>
        /// isDead: Check if the character is dead.
        /// onTurn: Check if it's his/her turn.
        /// </summary>
        public bool isDead, onTurn;

        /// <summary>
        /// Position on battle
        /// </summary>
        public Vector2 battlePosition;


        #endregion

        #region out_battle_attributes

        /// <summary>
        /// Character Name
        /// </summary>
        public string name;

        /// <summary>
        /// Characeter graphics
        /// </summary>
        public Texture2D sprite;

        /// <summary>
        /// Check if it's on battle.
        /// </summary>
        public bool onBattle;

        /// <summary>
        /// Position on map.
        /// </summary>
        public Vector2 mapPosition;

        #endregion

        #endregion

        #region methods

        /// <summary>
        /// Create a new character with default values.
        /// </summary>
        /// <param name="Content"></param>
        /// <param name="name"></param>
        public Character(ContentManager Content, string name)
        {
            this.name = name;
            this.health = 5;
            this.movement_points = 3;
            this.attack_points = 1;
            this.team = 0;
            this.strenght = 1;
            this.agility = 1;
            this.endurance = 1;
            this.luck = 1;
            this.isDead = false;
            this.onTurn = false;
            this.onBattle = false;
        }

        /// <summary>
        /// Create a new character by giving some values.
        /// </summary>
        /// <param name="Content"></param>
        /// <param name="name"></param>
        /// <param name="health"></param>
        /// <param name="movement_points"></param>
        /// <param name="attack_points"></param>
        public Character(ContentManager Content, string name, int health, int movement_points, int attack_points)
        {
            this.name = name;
            this.health = health;
            this.movement_points = movement_points;
            this.attack_points = attack_points;
            this.isDead = false;
            this.onTurn = false;
            this.onBattle = false;
        }


        /// <summary>
        /// Create a new character by giving all his attributes
        /// </summary>
        /// <param name="Content"></param>
        /// <param name="name"></param>
        /// <param name="health"></param>
        /// <param name="movement_points"></param>
        /// <param name="attack_points"></param>
        /// <param name="team"></param>
        /// <param name="strenght"></param>
        /// <param name="agility"></param>
        /// <param name="endurance"></param>
        /// <param name="luck"></param>
        /// <param name="isDead"></param>
        /// <param name="onTurn"></param>
        /// <param name="onBattle"></param>
        public Character(ContentManager Content, string name, int health, int movement_points, int attack_points, int team, int strenght, int agility, int endurance, int luck, bool isDead, bool onTurn, bool onBattle)
        {
            this.name = name;
            this.health = health;
            this.movement_points = movement_points;
            this.attack_points = attack_points;
            this.team = team;
            this.strenght = strenght;
            this.agility = agility;
            this.endurance = endurance;
            this.luck = luck;
            this.isDead = isDead;
            this.onTurn = onTurn;
            this.onBattle = onBattle;
        }



        /// <summary>
        /// Used to make the character walks to another position (walks only 1 sqm {32 pixels}).
        /// </summary>
        /// <param name="dir"></param>
        public void doWalk(int dir)
        {
            switch (dir)
            {
                case 0: // Up
                    {
                        this.mapPosition = new Vector2(this.mapPosition.X, this.mapPosition.Y - 32);
                        break;
                    }
                case 1: // Right
                    {
                        this.mapPosition = new Vector2(this.mapPosition.X + 32, this.mapPosition.Y);
                        break;
                    }
                case 2: // Down
                    {
                        this.mapPosition = new Vector2(this.mapPosition.X, this.mapPosition.Y + 32);
                        break;
                    }
                case 3: // Left
                    {
                        this.mapPosition = new Vector2(this.mapPosition.X - 32, this.mapPosition.Y);
                        break;
                    }
            }
        }


        public void Update(GameTime gameTime, MouseState mouse, MouseState old_mouse, KeyboardState keyboard, KeyboardState old_keyboard)
        {
            if (!onBattle)
            {

                if (mouse.LeftButton == ButtonState.Pressed && old_mouse.LeftButton != ButtonState.Pressed)
                {

                }

                #region Keyboard Movement

                if (keyboard.IsKeyDown(Keys.Up))
                {
                    doWalk(0);
                }

                if (keyboard.IsKeyDown(Keys.Right))
                {
                    doWalk(1);
                }

                if (keyboard.IsKeyDown(Keys.Down))
                {
                    doWalk(2);
                }

                if (keyboard.IsKeyDown(Keys.Left))
                {
                    doWalk(3);
                }

                #endregion

            }

        }


        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {

        }


        #endregion

    }
}
